export function getArrayValue(array, key) {
  var key = key || "value";
  var res = [];
  if (array) {
    array.forEach(function (t) {
      res.push(t[key]);
    });
  }
  return res;
}

export function array2obj(array, key) {
  var resObj = {};
  for (var i = 0; i < array.length; i++) {
    resObj[array[i][key]] = array[i];
  }
  return resObj;
}

export function getData(data) {
  var res = {
    series: [],
    yAxis: [],
  };
  for (let i = 0; i < data.length; i++) {
    res.series.push({
      name: "",
      left: "25%",
      top: "-30%",
      type: "pie",
      clockWise: false, //顺时加载
      hoverAnimation: false, //鼠标移入变大
      radius: [65 - i * 10 + "%", 62 - i * 10 + "%"],
      center: ["30%", "55%"],
      label: {
        show: false,
      },
      itemStyle: {
        label: {
          show: false,
        },
        labelLine: {
          show: false,
        },
        borderWidth: 5,
      },
      data: [
        {
          value: data[i].value > 80 ? data[i].value - 25 : data[i].value,
          name: data[i].name,
        },
        {
          value: 125 - data[i].value,
          name: "",
          itemStyle: {
            color: "rgba(0,0,0,0)",
            borderWidth: 0,
          },
          tooltip: {
            show: false,
          },
          hoverAnimation: false,
        },
      ],
    });
    res.series.push({
      name: "",
      left: "25%",
      top: "-30%",
      type: "pie",
      silent: true,
      z: 1,
      clockWise: false, //顺时加载
      hoverAnimation: false, //鼠标移入变大
      radius: [65 - i * 10 + "%", 62 - i * 10 + "%"],
      center: ["30%", "55%"],
      label: {
        show: false,
      },
      itemStyle: {
        label: {
          show: false,
        },
        labelLine: {
          show: false,
        },
        borderWidth: 5,
      },
      data: [
        {
          value: 7.5,
          itemStyle: {
            color: "rgba(25,46,84, .7)",
            borderWidth: 0,
          },
          tooltip: {
            show: false,
          },
          hoverAnimation: false,
        },
        {
          value: 2.5,
          name: "",
          itemStyle: {
            color: "rgba(0,0,0,0)",
            borderWidth: 0,
          },
          tooltip: {
            show: false,
          },
          hoverAnimation: false,
        },
      ],
    });
  }
  return res;
}
export function createOption(arrName, optionData, objData) {
  let option = {
    title: {
      text: "项目检测类别",
      textStyle: {
        color: "#fff",
        fontSize: 14,
        // fontWeight:'none'
      },
      top: "8",
      left: "10",
    },
    legend: {
      show: true,
      left: "center",
      bottom: 10,
      data: arrName,
      itemWidth: 8,
      itemHeight: 8,
      width: 250,
      padding: [0, 5],
      itemGap: 5,
      formatter: function (name) {
        return "{title|" + name + "}{value|" + objData[name].value + "%}";
      },
      textStyle: {
        rich: {
          title: {
            fontSize: 10,
            width: 55,
            lineHeight: 10,
            color: "#fff",
          },
          value: {
            fontSize: 10,
            width: 45,
            lineHeight: 10,
            color: "#fff",
          },
        },
      },
    },
    // tooltip: {
    //   show: true,
    //   trigger: "item",
    //   formatter: "{a}<br>{b}:{c}({d}%)",
    // },
    // color: colorArr,
    yAxis: [
      {
        type: "category",
        inverse: true,
        axisLine: {
          show: false,
        },
        axisTick: {
          show: false,
        },
        axisLabel: {
          interval: 0,
          inside: true,
          textStyle: {
            color: "#000",
            fontSize: 10,
          },
          show: true,
        },
        data: optionData.yAxis,
      },
    ],
    xAxis: [
      {
        show: false,
      },
    ],
    series: optionData.series,
  };
  return option;
}
export const colorArr = [
  "rgba(42, 232, 130, 1)",
  "rgba(255, 226, 0, 1)",
  "rgba(2, 119, 255, 1)",
  "rgba(255, 173, 217, 1)",
  "rgba(178, 111, 1, 1)",
  "rgba(135, 99, 233, 1)",
  "rgba(38, 98, 89, 1)",
];
